package com.ruoyi.camp.api;

import com.ruoyi.camp.domain.CFacility;
import com.ruoyi.camp.domain.CFacilityType;
import com.ruoyi.camp.domain.WxCampFacilityVo;
import com.ruoyi.camp.service.ICFacilityService;
import com.ruoyi.camp.service.ICFacilityTypeService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * 微信服务设施Controller
 *
 * @author ruoyi
 * @date 2024-11-01
 */
@RestController
@RequestMapping("/wechat/facility")
public class WxCFacilityController extends BaseController
{
    @Autowired
    private ICFacilityTypeService icFacilityTypeService;
    @Autowired
    private ICFacilityService icFacilityService;
    /**
     * 查询服务设施类型列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CFacilityType cFacilityType) {
        List<CFacilityType> list = icFacilityTypeService.selectCFacilityTypeAndCFacilityList(cFacilityType);
        return getDataTable(list);
    }
    /**
     * 修改服务设施
     */
    @PutMapping
    public AjaxResult edit(@RequestBody CFacility cFacility)
    {
        return toAjax(icFacilityService.updateCFacility(cFacility));
    }
    @GetMapping("/getinfo/{campid}")
    public AjaxResult getInfo(@PathVariable("campid") String campid) {
        if (campid == null) {
            return error("营地Id不能为空");
        }
        List<CFacilityType> list = icFacilityTypeService.selectCFacilityTypeAndCFacilityListByCampId(campid);
        return success(list);
    }
    @DeleteMapping("/delete/{campId}")
    public AjaxResult delete(@PathVariable("campId") String campid){
        if (campid == null) {
            return error("营地Id不能为空");
        }
        return toAjax(icFacilityTypeService.deleteCFacilityByCampId(campid));
    }
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WxCampFacilityVo wxCampFacilityVo){
        if (wxCampFacilityVo.getCampId() == null) {
            return error("营地Id不能为空");
        }
        if (wxCampFacilityVo.getFacilityIds() == null) {
            return error("服务设施Id不能为空");
        }
        return toAjax(icFacilityService.insertCampFacility(wxCampFacilityVo.getCampId(), wxCampFacilityVo.getFacilityIds()));
    }
}

